package com.manli.api.service;

import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.SQLReady;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.List;
import com.manli.api.pojo.Result;
import com.manli.api.util.ResultUtil;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import com.manli.api.pojo.QueryParams;
import com.manli.api.dao.AProvincesDao;
import com.manli.api.dto.AProvinces;
import org.springframework.transaction.annotation.Transactional;


@Service("aProvincesService")
public class AProvincesService {
    @Autowired
    AProvincesDao aProvincesDao;
    @Autowired
    SQLManager sqlManager;

    
    public Result queryPage(QueryParams params) {
        /**
        * sql中表名需要修改
        */
        StringBuffer sql = new StringBuffer("select * from aProvinces where 1=1 ");

        SQLReady sqlReady = new SQLReady(sql.toString());

        PageQuery<AProvinces> pageQuery = new PageQuery<AProvinces>(params.getPage(),params.getLimit());
        PageQuery<AProvinces> query =sqlManager.execute(sqlReady,AProvinces.class,pageQuery);
        return ResultUtil.success(query.getList(),query.getTotalRow());
    }

    
    public Result queryAll() {
        List<AProvinces> list = aProvincesDao.all();
        return ResultUtil.success(list);
    }

    
    public Result getById(String code) {
        AProvinces aProvinces = aProvincesDao.single(code);
        return ResultUtil.success(aProvinces);
    }

    @Transactional
    public Result save(AProvinces aProvinces) {
        aProvincesDao.insert(aProvinces);
        return ResultUtil.success();
    }

    @Transactional
    public Result updateById(AProvinces aProvinces) {
        aProvincesDao.updateTemplateById(aProvinces);
        return ResultUtil.success();
    }
    @Transactional
	public Result updateTemplateById(AProvinces aProvinces) {
        aProvincesDao.updateTemplateById(aProvinces);
        return ResultUtil.success();
    }
    @Transactional
    public Result removeById(String code) {
        aProvincesDao.deleteById(code);
        return ResultUtil.success();
    }

    @Transactional
    public Result removeByIds(List<String> ids) {
        for (String id:ids) {
            aProvincesDao.deleteById(id);
        }
        return ResultUtil.success();
    }



}
